package ro.bluecube.admlocal.delegates;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.logging.Logger;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import ro.bluecube.admlocal.persons.PersonsServiceRemote;
import ro.bluecube.admlocal.persons.entity.Person;

	/**
	 * @author anton
	 * 
	 */
	public class PersonDelegate {

		private static final Logger log = Logger.getLogger(PersonDelegate.class.getName());
		
		PersonsServiceRemote service;

		public PersonDelegate() {
			super();
			final String jndiName = "PersonsServiceImpl/remote";

			Context ic;
			try {
				ic = new InitialContext(System.getProperties());
				Object obj = ic.lookup(jndiName);

				service = (PersonsServiceRemote) obj;
			} catch (NamingException e) {
				log.info("naming exception");
				service = null;
			}
		}

		@SuppressWarnings("unchecked")
		public Collection<Person> findAllPersons() {
			List personsList = null;
			if (service!=null){
				personsList = (List) service.getAllPersons();
			} else {
				personsList = new ArrayList<Person>();
			}
			return personsList;
		}
	}
